﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Data;

namespace WS.BLL.EntitiesBLL
{
    public class ThanhvienBLL
    {
        public string EncodeMD5(string chuoi)
        {
            MD5 md5 = MD5.Create();
            byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(chuoi));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                sb.Append(data[i].ToString("x2"));
            }
            return sb.ToString();
        }

        public UTL.Session CheckLogin(DataTable dtb, string user, string pass)
        {
            var sss = new WS.UTL.Session();

            pass = EncodeMD5(pass);
            string tk = dtb.Rows[0]["taikhoan"] + "";
            string mk = dtb.Rows[0]["matkhau"] + "";
            string hoten = dtb.Rows[0]["hoten"] + "";
            int vaitro = Convert.ToInt32(dtb.Rows[0]["vaitro_id"]);

            sss.Login = mk == pass ? true : false;
            sss.Acc = tk;
            sss.Pass = mk;
            sss.Name = hoten;
            sss.Role = (WS.UTL.Session.Roles)vaitro;
            
            return sss;
        }
    }
}
